package com.gjy.amqp.simple.producer;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-05-17 09:06:40
 */
public class HelloWorldPublish {

    private final static String QUEUE_NAME = "HelloWorld";
    private static final Logger log = LoggerFactory.getLogger(HelloWorldPublish.class);

    public static void main(String[] argv) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.253.142");
        factory.setUsername("admin");
        factory.setPassword("admin");
        factory.setVirtualHost("/");
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {

            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            String message = "Hello World!";
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            log.info("[x] send: {}", message);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
